feat(llm): LLM module protocol optimization - #429
feat(llm): LLM module protocol optimization#429openjiuwen-sync-bot[bot] wants to merge 1 commit into
Conversation
|
|
1 similar comment
|
|
|
head_sha: 变更摘要此 PR 主要对 LLM 模块的协议层进行了优化:引入多认证模式( 主要改动
|
|
head_sha: 代码审查审查总结发现问题汇总
各文件审查结论
整体风险评估:中低风险核心路由逻辑(
💬 仅评论 |
| image_block = _image_source_block(image_value) | ||
| if image_block is not None: | ||
| blocks2.append(image_block) | ||
| continue |
There was a problem hiding this comment.
head_sha: ca46e3235f9d63ad64baf4aefce92ccf32a4619a
🟡 Medium Priority
变更位置:openjiuwen/core/foundation/llm/model_clients/anthropic_model_client.py 第 237-241 行的 _content_to_blocks 函数。
问题链:
- 当
item_type为"image_url"/"input_image"/"image"时,提取image_value - 若
image_value is not None,调用_image_source_block(image_value)进行转换 - 若
_image_source_block返回None(例如 image_url 的 url 字段缺失或为空字符串),该分支执行continue,跳过了原有的blocks2.append(dict(item))回退路径 - 结果:原始图像项被静默丢弃,消息中不包含任何图像内容
触发条件:image_url 的值为 {}(空 dict)、{"url": ""}(空 URL)、或 {"url": None} 等边缘输入。
失败模式:用户/上游代码以为发送了图像,但实际请求中该图像消失,模型收不到视觉上下文,产生难以排查的结果偏差。
建议:将 continue 移到 if image_block is not None: 块内部,使转换失败时能回退到 blocks2.append(dict(item));或者当 _image_source_block 返回 None 且有 image_value 时抛出明确错误。
| continue | |
| if image_value is not None: | |
| image_block = _image_source_block(image_value) | |
| if image_block is not None: | |
| blocks2.append(image_block) | |
| continue |
|
head_sha: 代码审查The indentation confirms the issue: 审查完毕审查发现汇总
各变更文件审查结果
整体风险判断中低风险。唯一的 P2 问题是一个边界条件缺陷(图像 URL 为空时静默丢弃),触发概率较低且影响范围有限。其余变更——包括 Anthropic thinking/replay 机制、端点 profile 路由、auth_mode 校验、metadata 传播——设计合理、实现正确,测试覆盖充分。建议在合入前修复
💬 仅评论 |
| image_value = item.get("data_url", item.get("image")) | ||
| if image_value is not None: | ||
| image_block = _image_source_block(image_value) | ||
| if image_block is not None: |
There was a problem hiding this comment.
head_sha: ca46e3235f9d63ad64baf4aefce92ccf32a4619a
🟡 Medium Priority
变更位置:openjiuwen/core/foundation/llm/model_clients/anthropic_model_client.py 第 237-241 行。
问题链:
- 当
item_type为"image_url"/"input_image"或"image"(无source)时,image_value被设置为从 item 中提取的图像值(第 233-236 行)。 - 若
image_value is not None(第 237 行),则调用_image_source_block(image_value)尝试转换。 - 若转换成功(
image_block is not None),则追加到 blocks(第 239-240 行),然后执行continue(第 241 行)跳过通用的blocks2.append(dict(item))——这是正确的。 - 但若转换失败(
image_block is None),continue仍然执行,同样跳过了第 242 行的blocks2.append(dict(item)),导致该图像项被静默丢弃。
触发条件:当 image_value 为非 None 但 _image_source_block 返回 None 时。具体场景包括:
失败模式:用户传入的图像项被静默丢弃,可能导致 API 调用中的内容丢失,且无任何错误提示。
此问题与上一轮审查中指出的问题一致,当前 diff 中未修复:continue 仍然在 if image_block is not None: 块外部。
建议:将 continue 移到 if image_block is not None: 块内部,使转换失败时能回退到 blocks2.append(dict(item))。修改后逻辑:若 image_block is not None,追加转换后的块并 continue;否则继续执行到通用的 append。
| if image_block is not None: | |
| if image_block is not None: | |
| blocks2.append(image_block) | |
| continue |
| image_value = item.get("data_url", item.get("image")) | ||
| if image_value is not None: | ||
| image_block = _image_source_block(image_value) | ||
| if image_block is not None: |
There was a problem hiding this comment.
head_sha: ca46e3235f9d63ad64baf4aefce92ccf32a4619a
🟡 Medium Priority
变更位置:openjiuwen/core/foundation/llm/model_clients/anthropic_model_client.py 第 237-241 行的 _content_to_blocks 函数。
问题链:
- 当
image_value is not None时进入图像转换分支(第 237 行) - 调用
_image_source_block(image_value)进行转换(第 238 行) - 若转换成功(
image_block is not None),则追加image_block(第 239-240 行) - 无论转换成功与否,都执行
continue(第 241 行),跳过了底部的兜底逻辑blocks2.append(dict(item))(第 242 行) _image_source_block在以下情况返回None:传入的是没有"url"键的 Mapping、空字符串、或非字符串类型——这些情况下图像项被静默丢弃
触发条件:用户传入类似 {"type": "image_url", "image_url": {}} 或 {"type": "image_url", "image_url": {"url": None}} 的消息内容。
此问题在上一轮审查中已被报告但未修复。
建议:将 continue 移到 if image_block is not None: 块内部,使转换失败时能回退到 blocks2.append(dict(item)) 兜底逻辑。或者当 image_block is None 时记录警告并使用兜底。
| if image_block is not None: | |
| if image_value is not None: | |
| image_block = _image_source_block(image_value) | |
| if image_block is not None: | |
| blocks2.append(image_block) | |
| continue |
ca46e32 to
d5193af
Compare
d5193af to
18ab1fb
Compare
18ab1fb to
90b9bb6
Compare
Paired: GitHub #429 ↔ GitCode !2257
What type of PR is this?
/kind bug
Self-checklist:(请自检,在[ ]内打上x,我们将检视你的完成情况,否则会导致pr无法合入)